package cn.pconline.autoclub.entity;

import org.apache.commons.lang.StringUtils;
import org.gelivable.dao.Column;
import org.gelivable.dao.Entity;
import org.gelivable.dao.Id;

/**
 *
 * @author <a href="mailto:chensy0203@163.com">chensy</a>
 */
@Entity(tableName = "ac_topic_image", split = "Mod:topicId:10")
public class TopicImage {

    @Id
    @Column(name = "image_id")
    private long imageId; // ID
    @Column(name = "topic_id")
    private long topicId; // 帖子ID
    @Column(name = "url")
    private String url; // url
    @Column(name = "width")
    private int width; // 宽
    @Column(name = "height")
    private int height; // 高
    @Column(name = "seq")
    private int seq; // 顺序
    public static final int MAX_IMAGE = 3;

    public long getImageId() {
        return imageId;
    }

    public void setImageId(long imageId) {
        this.imageId = imageId;
    }

    public long getTopicId() {
        return topicId;
    }

    public void setTopicId(long topicId) {
        this.topicId = topicId;
    }

    public String getUrl() {
        return getImgage(url);
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getSeq() {
        return seq;
    }

    public void setSeq(int seq) {
        this.seq = seq;
    }

    public static String getImgage(String image) {
        if (StringUtils.isBlank(image)) {
            return image;
        }
        if (image.indexOf("/bbs6/") == -1
                && image.indexOf("/autoclub/") == -1
                && image.indexOf("/usercenter/") == -1) {
            //非论坛、非车友会、非个人中心 上传的图片URL不显示
            return "";
        }
        return image;
    }
}
